/**
 * Created by ying on 16-8-26.
 */
app.controller('payCtrl', function($scope,$location) {
    $scope.cart=new Cart();
    $scope.show_count=function(){
        var count=$scope.cart.get_sum_count();
        $scope.sum_count=count ||0;
    }
    $scope.goods_infos=_.values($scope.cart.goods_info)
    var save_info=get_save_info();
    $scope.save_infos=save_info;
    $scope.judgment_subtotal=function(item){
        if(item.pro_count!=0){
            return true
        }
    }
    var sum_money=$scope.cart.get_sum_money();
    $scope.sum_money=sum_money.toFixed(2);
    var save_money=$scope.cart.get_save_money();
    $scope.save_money=save_money.toFixed(2);
    $scope.confirm=function(){
        localStorage.clear();
        $location.path('/product_list');
    }
    if(save_info.length!=0){
        $scope.free=true
    }
    function get_save_info(){
        var save_info=[];
        _.each($scope.cart.goods_info,function(info){
            if(info.pro_count!=0){
                save_info.push(info);
            }
        })
        return save_info;
    }
    function get_time(){
        dateDigitToString = function (num) {
            return num < 10 ? '0' + num : num;
        };
        var currentDate = new Date(),
            year = dateDigitToString(currentDate.getFullYear()),
            month = dateDigitToString(currentDate.getMonth() + 1),
            date = dateDigitToString(currentDate.getDate()),
            hour = dateDigitToString(currentDate.getHours()),
            minute = dateDigitToString(currentDate.getMinutes()),
            second = dateDigitToString(currentDate.getSeconds()),
            formattedDateString = year + '年' + month + '月' + date + '日 ' + hour + ':' + minute + ':' + second;
        return formattedDateString;
    }
    var date=get_time();
    $scope.date=date;

});